<script setup>
import {ref,onMounted} from 'vue'
import {HomeFilled,Tools,School,Money,Avatar,Expand,Fold,ArrowDown} from "@element-plus/icons-vue";
//导入面包屑组件
import Breadcrumb from "../../components/Breadcrumb.vue";
/* 1. 把图表组件引进来 */
import Dashboard from '../../components/Dashboard.vue'
import router from "@/router/index.js";
//判断折叠按钮是否展开
const isCollapse=ref(false)
    //panduan标题是否显示
const title=ref(true)
//定义接受对象
const user=ref({})
onMounted(() => {
  //获取本地存储的信息
  const userStr=localStorage.getItem("user")
  if(userStr){
    user.value=JSON.parse(userStr)
  }
})
//退出登录
const logout=()=>{
  //清楚本地数据跳转登录页面
  localStorage.removeItem("user")
  router.push("/")
}

// 定义方法控制左侧菜单的展开与显示
const collapse=()=>{
  isCollapse.value=!isCollapse.value
  if(isCollapse.value){
    isCollapse.value =true
    title.value=false
  }else{
    title.value=false
  }
}

</script>
<template>
  <div class="common-layout">
    <el-container>
      <el-aside :width="isCollapse?'64px':'200px'">
<!--        左侧菜单栏-->
        <div class="system-title">
          <img src="../../assets/images/logo.png">
            <span style="color: white">软件工程学院</span>
        </div>
        <el-menu  :collapse="isCollapse" unique-opened :collapse-transition="collapse-transition" default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" router>
          <el-menu-item index="/home" style="margin-left: 0px">
              <el-icon><HomeFilled/></el-icon>
            <template #title>
              <span>首页</span>
            </template>
          </el-menu-item>
          <el-sub-menu index="2">
            <template #title>
              <el-icon><Tools/></el-icon>
              <span>系统管理</span>
            </template>
            <el-menu-item index="/user">用户管理</el-menu-item>
            <el-menu-item index="1-2">通知公告</el-menu-item>
            <el-menu-item index="1-3">专业管理</el-menu-item>
            <el-menu-item index="1-4">班级管理</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="3">
            <template #title>
              <el-icon><School /></el-icon>
              <span>宿舍管理</span>
            </template>
            <el-menu-item index="1-1">宿舍管理</el-menu-item>
            <el-menu-item index="1-2">入住管理</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="4">
            <template #title>
              <el-icon><Money/></el-icon>
              <span>财务管理</span>
            </template>
            <el-menu-item index="1-1">缴费管理</el-menu-item>
            <el-menu-item index="1-2">缴费记录</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="5">
            <template #title>
              <el-icon><Avatar/></el-icon>
              <span>学生管理</span>
            </template>
            <el-menu-item index="1-1">学生信息</el-menu-item>
            <el-menu-item index="1-2">报道信息</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>



      <el-container>
        <el-header>
          <div class="collapse"@click="collapse">
            <el-icon :size="28" v-if="isCollapse" style="cursor: pointer"><Expand/></el-icon>
            <el-icon :size="28" v-if="!isCollapse" style="cursor: pointer"><Fold/></el-icon>
          </div>
          <span>新生报到服务平台</span>
<!--          右侧用户信息-->
          <div class="user-info">
            <img src="../../assets/images/u169.svg">
            <el-dropdown>
                <span class="el-dropdown-link">
                 {{user.username}}
                 <el-icon><ArrowDown /></el-icon>
                </span>
                <template #dropdown>
                  <el-dropdown-menu style="margin-top: 5px">
                    <el-dropdown-item>个人信息</el-dropdown-item>
                    <el-dropdown-item>修改密码</el-dropdown-item>
                    <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
            </el-dropdown>
          </div>

        </el-header>
        <el-main>
          <Breadcrumb></Breadcrumb>
          <!--          路由视图-->
          <router-view></router-view>
<!--          仪表盘组件-->
          <Dashboard v-if="$route.path === '/home'"></Dashboard>

        </el-main>
        <el-footer>Footer</el-footer>
      </el-container>
    </el-container>
  </div>
</template>
<style scoped>
  .common-layout{
    width: 100vw;
    height: 100vh;
  }
/*左侧菜单样式*/

  .el-container {
    background-color: white;
    color: #333;
    height: 730px;
    overflow: hidden;/*溢出部分隐藏*/

  }
  .el-header {
    background-color:rgb(242, 243, 245);
    color: #333;
    display: flex;
    line-height: 60px;
    padding: 0px;
    position: relative;
  }
  .el-main{
    background-color:#e9efef;
    display: flex;
    color: #333;
    flex-direction: column;
    padding: 0;
  }
  .el-footer{
    background-color:#fefdf9 ;
    display: flex;
    color: #333;
    line-height: 60px;
  }

  .el-menu-item{
  margin-left: 8px;
  }
  .system-title{
    width: 200px;
    height: 60px;
    background-color: rgb(143,1,0);
    line-height: 60px;
    position: relative;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    text-indent: 48px;
  }
  .system-title img{
    width: 50px;
    position: absolute;
    left: 10px;
    top: 5px;
  }
  .collapse{
    padding-top: 8px;
    padding-left: 3px;
  }
  .el-header span{
    display: inline-block;
    line-height: 60px;
    font-size: 20px;
    margin-left: 10px;
  }
  .user-info{
    position: absolute;
    right: 20px;
    top: 5px;
  }
.el-dropdown-link{
  cursor: pointer;
  outline: none;
}

</style>